<template>
  <div class="u-p-20">
    <el-card shadow="never">
      <div slot="header">
        <span>
          <b class="u-f-16">商品列表</b>
        </span>
      </div>

      <el-form :inline="true" :model="queryForm" size="small" class="u-text-center">
        <el-form-item label="上线状态">
          <el-select v-model="queryForm.status" clearable>
            <el-option label="全部" value></el-option>
            <el-option label="上线" value="1"></el-option>
            <el-option label="下线" value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="商品名称">
          <el-input v-model="queryForm.keyword" placeholder="输入商品标题查询" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="getPageData(true)">查询</el-button>
        </el-form-item>
      </el-form>

      <el-table :data="tableData" class="u-mt-10" v-viewer>
        <el-table-column label="id" prop="id" width="50"></el-table-column>
        <el-table-column label="选择商品" width="120">
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="select_data(scope.row)">选择</el-button>
          </template>
        </el-table-column>
        <el-table-column label="图片">
          <template slot-scope="scope">
            <el-image
              style="max-width: 150px;"
              :src="scope.row.goods_img"
              :data-src="scope.row.goods_img"
              fit="cover"
              lazy
            ></el-image>
          </template>
        </el-table-column>

        <el-table-column label="商品分类" prop="goods_type_name"></el-table-column>

        <el-table-column label="标题" prop="goods_title"></el-table-column>

        <el-table-column label="市场价" prop="goods_bazaar_price"></el-table-column>
        <el-table-column label="库存" prop="goods_storage"></el-table-column>
        <el-table-column label="上线状态">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.goods_status==1" type="success">上线</el-tag>
            <el-tag v-else type="info">下线</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="热门推荐">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.goods_hot_status==1" type="success">推荐</el-tag>
            <el-tag v-else type="info">不推荐</el-tag>
          </template>
        </el-table-column>
      </el-table>

      <div class="u-mt-20 u-text-center">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handlePageChange"
          :current-page="currentPage"
          :page-sizes="[10, 20, 30, 40, 50]"
          :page-size="limit"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        ></el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script>
import commonPage from "@/mixins/common-page";

export default {
  mixins: [commonPage],
  props: {
    isprops: Boolean,
    activity: String,
    agency: String
  },
  data() {
    return {
      apiName: "goods",
      queryForm: {
        activity: "",
        agency: "",
        status: "",
        keyword: ""
      }
    };
  },
  methods: {
    beforeOnLoad() {
      if (this.activity) {
        this.queryForm.activity = this.activity;
      }
      if (this.agency) {
        this.queryForm.agency = this.agency;
      }
    },
    select_data(row) {
      //选中数据
      this.$emit("goods_select", row); //返回父组件
    },
    //刷新数据
    upDateList() {
      let is_up = true;
      this.getPageData(is_up).then(() => {
        this.afterOnLoad();
      });
    }
  }
};
</script>
